package com.ruoyi.app.controller;

import com.ruoyi.app.domain.AppHtPoints;
import com.ruoyi.app.service.IAppHtPointsService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 积分记录Controller
 *
 * @author ruoyi
 * @date 2025-01-09
 */
@RestController
@RequestMapping("/system/AppPoints")
public class AppHtPointsController extends BaseController {
    @Autowired
    private IAppHtPointsService appHtPointsService;

/**
 * 查询积分记录列表
 */
@PreAuthorize("@ss.hasPermi('system:AppPoints:list')")
@GetMapping("/list")
    public TableDataInfo list(AppHtPoints appHtPoints) {
        startPage();
        List<AppHtPoints> list = appHtPointsService.selectAppHtPointsList(appHtPoints);
        return getDataTable(list);
    }

    /**
     * 导出积分记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:AppPoints:export')")
    @Log(title = "积分记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppHtPoints appHtPoints) {
        List<AppHtPoints> list = appHtPointsService.selectAppHtPointsList(appHtPoints);
        ExcelUtil<AppHtPoints> util = new ExcelUtil<AppHtPoints>(AppHtPoints. class);
        util.exportExcel(response, list, "积分记录数据");
    }

    /**
     * 获取积分记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:AppPoints:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return success(appHtPointsService.selectAppHtPointsById(id));
    }

    /**
     * 新增积分记录
     */
    @PreAuthorize("@ss.hasPermi('system:AppPoints:add')")
    @Log(title = "积分记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppHtPoints appHtPoints) {
        return appHtPointsService.insertAppHtPoints(appHtPoints);
    }

    /**
     * 修改积分记录
     */
    @PreAuthorize("@ss.hasPermi('system:AppPoints:edit')")
    @Log(title = "积分记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppHtPoints appHtPoints) {
        return toAjax(appHtPointsService.updateAppHtPoints(appHtPoints));
    }

    /**
     * 删除积分记录
     */
    @PreAuthorize("@ss.hasPermi('system:AppPoints:remove')")
    @Log(title = "积分记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(appHtPointsService.deleteAppHtPointsByIds(ids));
    }
}
